home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 October / macformat-055.iso / mac / Shareware Plus / Developers / VideoToolbox / (Demos) / TimeCPU.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  30.6 KB  |  1,193 lines  |  [TEXT/CWIE]

  1. /*
  2. TimeCPU.c
  3. Denis G. Pelli, 1991-1995
  4. This routine uses my Timer.c to measure the timing of basic CPU
  5. operations and several random number generators. (Apple's Microseconds() routine
  6. would do just as well, instead of Timer.c, but wasn't available when I wrote this.) 
  7. The timing seems to be very accurate. It ought to be as accurate as the
  8. frequency of the oscillator in the VIA chip. However, I haven't checked the
  9. timing against a known standard.
  10.  
  11. The Fixed data type is predefined by Apple as a long (i.e. 32 bits) with an assumed 
  12. decimal point in the middle.
  13.  
  14. The access to video memory overwrites a small part of your main screen, the
  15. first 40 bytes. This will be in the upper left hand corner of your display, and
  16. will usually be barely noticeable. I like seeing that, as it confirms that the
  17. program really is accessing the video memory.
  18.  
  19. This program requests a memory partition of 900K. It will run in less, but will
  20. then do fewer iterations.
  21.  
  22. NOTE: This file is part of the VideoToolbox archive of C sources for the Mac. 
  23. You can download the whole VideoToolbox from any Info-Mac mirror:
  24. ftp://mirror.apple.com/mirrors/info-mac/dev/lib/video-toolbox-95-11-10-c.hqx
  25. ftp://mirrors.aol.com/pub/info-mac/dev/lib/video-toolbox-95-11-10-c.hqx
  26.  
  27. The glue libraries NameRegistryLib and DriverServicesLib are in the VideoToolbox Libs folder. 
  28.  
  29. HISTORY:
  30. 1/91    dgp    wrote it
  31. 2/16/91    dgp    added fpu test, to fail gracefully if compiled with FPU support, but FPU
  32.             is not present.
  33. 3/4/91    dgp    added timing of random number generators
  34. 8/6/91    dgp    added timing of RandFill.
  35. 8/24/91    dgp    Made compatible with THINK C 5.0.
  36. 1/25/92    dgp    Calibrate and correct for the slowness of TimeIt(). 
  37.             Measure and subtract off the small loop overhead.
  38.             Identify machine and compiler.
  39.             Automatically append results to TimeCPU.data file.
  40. 1/29/92    dgp    Time move from memory to video memory, for showing movies.
  41.             Added transcendental functions since Radius 8881 init and System 7.01
  42.             speed them up dramatically and the Quadra is reputed to
  43.             do them very slowly.
  44. 1/30/92    dgp    Access video memory only in 32-bit mode, to avoid crashes.
  45. 8/19/92    dgp    time the 68881 instructions _sin, _sqrt, _exp, _log
  46.             Use new Timer.c instead of old TimeIt.c
  47. 8/28/92    dgp    updated to use new reentrant Timer.c
  48. 11/18/92 dgp renamed output file to “TimeCPU results”
  49. 1/11/93    dgp    check for presence of 68020. Put Gestalt tests in main, without
  50.             any fpu usage, since program was crashing when fpu was absent
  51.             before getting to the fpu test. (Supposedly that was fixed
  52.             in THINK C 5. Oh well.)
  53. 2/7/93    dgp    added timing of SetPixelsQuickly().
  54. 7/9/93    dgp check for 32-bit addressing capability.
  55. 3/13/94    dgp    added timing of short arithmetic, and put conditionals around each section.
  56. 6/1/94    dgp    added timing of BlockMoveData().
  57. 6/14/94    dgp    can32 is now computed by calling TrapAvailable(_SwapMMUMode), which 
  58.             returns the correct answer even on Macs with dirty ROMs.
  59. 7/31/94    dgp made compatible with new SANE.h in Universal Headers.
  60. 9/5/94 dgp removed assumption in printf's that int==short.
  61. 10/2/94    dgp deleted RandomX() since it's part of SANE, which doesn't exist on PowerPC,
  62.             and, in any event, was uselessly slow on 68k machines. Tidied up the
  63.             printout for readability even for computers as fast as the PowerPC.
  64. 4/9/95 dgp added a few tests relevant to nrand(). Increased n. Polished the printout a bit.
  65. 4/11/95 dgp changed declaration of bufferHandle from void ** to Handle, for compatibility with
  66. old pre-universal apple headers.
  67. 5/23/95 dgp Apple changed the prototype in the header file from SwapMMUMode(char *) to 
  68.             SwapMMUMode(signed char *). To retain compatibility with both old and new
  69.             headers, I cast the argument (void *).
  70. 11/20/95 dgp added timing of moves using float pointers, since they're supposed to be fast on the PowerPCs.
  71. 1/28/96 dgp only call BlockMoveDataUncached on PCI Macs; otherwise use BlockMoveData.
  72. 3/4/96 dgp made compatible with THINK C 7.
  73. 4/10/97    dgp    Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
  74. */
  75. #include "VideoToolbox.h"
  76. #ifndef __TRAPS__
  77.     #include <Traps.h>    // _SwapMMUMode
  78. #endif
  79. //#include <Menus.h>    // DrawMenuBar
  80. void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  81. void ExpandRect(Rect *r,double hMag,double vMag);
  82. void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  83.  
  84. void TimeCPU(void);
  85. #if GENERATINGPOWERPC
  86. // BlockMoveDataUncached is only available on PowerPC. Apparently video buffers are "uncacheable" and
  87. // BlockMoveData uses an instruction that is emulated slowly in that case.
  88.     extern void BlockCopy(const void *srcPtr, void *destPtr, Size byteCount);
  89.     extern void BlockMoveDataUncached(const void *srcPtr, void *destPtr, Size byteCount);
  90. #else
  91.     #define BlockCopy BlockMoveData
  92.     #define BlockMoveDataUncached BlockMoveData
  93. #endif
  94. #ifndef __CODEFRAGMENTS__
  95.     #include <CodeFragments.h>
  96. #endif
  97.  
  98. void main(void)
  99. {
  100.     long value;
  101.  
  102.     Require(gestaltOriginalQD);
  103.     Gestalt(gestaltTimeMgrVersion,&value);
  104.     if(value<gestaltRevisedTimeMgr)
  105.         PrintfExit("Sorry, your System is too old; I need at least \n"
  106.             "the Revised Time Manager.\n");
  107.     TimeCPU();
  108. }
  109.  
  110. void TimeCPU(void)
  111. {
  112.     long n,quickDraw;
  113.     short i;
  114.     register long *paL,*pbL,iL,jL,kL,mL;
  115.     double x,y,z;
  116.     Fixed xF,yF,zF;
  117.     Handle bufferHandle;
  118.     void *buffer,*buffer2;
  119.     char Buffer[32];
  120.     FILE *o[2],*dataFile;
  121.     GDHandle device;
  122.     double s,s0,overhead;
  123.     Timer *timer;
  124.     OSErr osErr,error;
  125.     long value;
  126.     Boolean can32;
  127.     Boolean pci;    // Is this a PCI Mac? Only the PCI Macs have BlockMoveDataUncached.
  128.  
  129.     MaximizeConsoleHeight();
  130.     /* INITIALIZE QuickDraw */
  131.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  132.         console_options.ncols = 90;
  133.     #elif __MWERKS__
  134.         SIOUXSettings.columns=90;
  135.     #elif
  136.         InitGraf(&qd.thePort);
  137.         InitFonts();
  138.         InitWindows();
  139.         InitCursor();
  140.     #endif
  141.     printf("Welcome to TimeCPU.\n");
  142.     assert(StackSpace()>4000);
  143.     can32=TrapAvailable(_SwapMMUMode);
  144.     timer=NewTimer();
  145.     #define gestaltNameRegistryVersion 'nreg'    // support old versions of Gestalt.h
  146.     error=Gestalt(gestaltNameRegistryVersion,&value);
  147.     pci=(error==0);    // are there PCI slots?
  148.     #if CFMSYSTEMCALLS
  149.         if(GENERATINGPOWERPC && pci){
  150.             // The BlockMoveDataUncached glue is in a shared library.
  151.             // If the DriverServicesLib is weak-linked, and missing, we need to
  152.             // check for the library, to prevent a crash if we try to access the 
  153.             // library's exports.
  154.             CFragConnectionID        connID;
  155.             Ptr                        mainAddr;
  156.             Str255                    errName;
  157.             long templong;
  158.             int error;
  159.             
  160.             error=Gestalt(gestaltCFMAttr,&templong);    // Code Fragment Manager?
  161.             if(!error){
  162.                 error=GetSharedLibrary((ConstStr63Param)"\pDriverServicesLib"
  163.                     ,kAnyCFragArch,kFindCFrag,&connID,&mainAddr,errName);
  164.                 if(error)PrintfExit("\nCouldn't load %#s. GetSharedLibrary error=%d\n\007",errName,(int)error);
  165.             }
  166.         }
  167.     #endif
  168.     o[0]=stdout;
  169.     o[1]=dataFile=fopen("TimeCPU results","a");    /* Append to data file */
  170.     if(dataFile!=NULL){
  171.         printf("Key results will be appended to “TimeCPU results” file.\n\n");
  172.         SetFileInfo("TimeCPU results",'TEXT','ttxt');
  173.     }
  174.     else printf("Could not open “TimeCPU results” file\n\n");
  175.     ffprintf(o,"\n%s\n",BreakLines(IdentifyMachine(),80));
  176.     ffprintf(o,"%s\n\n",BreakLines(IdentifyCompiler(),80));
  177.     ffprintf(o,"      Time    Operation\n");
  178.     srand(clock());
  179.     y=sqrt(2.0);
  180.     z=sqrt(3.0);
  181.     kL=y*1000.;
  182.     mL=z*10.;
  183.     RandFill(Buffer,sizeof(Buffer));
  184.         
  185.     n=100000;    // REDUCE THIS NUMBER TO SPEED UP THE TESTING, BUT REDUCE PRECISION.
  186.     overhead=0.0;
  187.     StartTimer(timer);
  188.     for(iL=n/10;iL>0;iL--) ;
  189.     overhead=StopTimerSecs(timer)/n-overhead;    // the loop overhead per operation
  190.  
  191. // Time various ways of moving memory    
  192.     for(;n>0;){
  193.         bufferHandle=NewHandle(2*sizeof(long)*n);
  194.         if(bufferHandle==NULL)bufferHandle=TempNewHandle(2*sizeof(long)*n,&osErr);
  195.         if(bufferHandle!=NULL)break;
  196.         n/=2;
  197.         printf("Reducing iterations to %ld to fit in available memory.\n",n);
  198.     }
  199.     assert(bufferHandle!=NULL);
  200.     HLockHi(bufferHandle);
  201.     buffer=*bufferHandle;
  202.     buffer=(void *)(((unsigned long)buffer+15) & ~15UL);    // round up to multiple of 16
  203.     buffer2=(long *)buffer+n;
  204.     buffer2=(void *)((unsigned long)buffer2 & ~15UL);    // round down to multiple of 16
  205.     {
  206.         StartTimer(timer);
  207.         BlockMove(buffer2,buffer,4*n);
  208.         s=StopTimerSecs(timer);
  209.         ffprintf(o,"%11.3f ms    BlockMove(,,%ld);    // %.1f MB/s\n"
  210.             ,s*1e3,n*4,n*4/1024./1024./s);
  211.     }
  212.     {
  213.         StartTimer(timer);
  214.         BlockMoveData(buffer2,buffer,4*n);
  215.         s=StopTimerSecs(timer);
  216.         ffprintf(o,"%11.3f ms    BlockMoveData(,,%ld);    // %.1f MB/s\n"
  217.             ,s*1e3,n*4,n*4/1024./1024./s);
  218.     }
  219.     {
  220.         register double *paF,*pbF;
  221.  
  222.         n/=sizeof(*paF)/4;
  223.         paF=(void *)buffer;
  224.         pbF=(void *)buffer2;
  225.         StartTimer(timer);
  226.         for(iL=n/10;iL>0;iL--){
  227.             *paF++=*pbF++;
  228.             *paF++=*pbF++;
  229.             *paF++=*pbF++;
  230.             *paF++=*pbF++;
  231.             *paF++=*pbF++;
  232.             *paF++=*pbF++;
  233.             *paF++=*pbF++;
  234.             *paF++=*pbF++;
  235.             *paF++=*pbF++;
  236.             *paF++=*pbF++;
  237.         }
  238.         s=StopTimerSecs(timer)/n-overhead;
  239.         ffprintf(o,"%11.3f µs    *paF++=*pbF++;        // double, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  240.         n*=sizeof(*paF)/4;
  241.     }
  242.     {
  243.         register double *paF,*pbF;
  244.         unsigned long bytes=sizeof(*paF);
  245.  
  246.         n/=sizeof(*paF)/4;
  247.         paF=(void *)buffer;
  248.         pbF=(void *)buffer2;
  249.         paF--;pbF--;
  250.         StartTimer(timer);
  251.         for(iL=n/10;iL>0;iL--){
  252.             *++paF=*++pbF;
  253.             *++paF=*++pbF;
  254.             *++paF=*++pbF;
  255.             *++paF=*++pbF;
  256.             *++paF=*++pbF;
  257.             *++paF=*++pbF;
  258.             *++paF=*++pbF;
  259.             *++paF=*++pbF;
  260.             *++paF=*++pbF;
  261.             *++paF=*++pbF;
  262.         }
  263.         s=StopTimerSecs(timer)/n-overhead;
  264.         ffprintf(o,"%11.3f µs    *++paF=*++pbF;        // double, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  265.         n*=sizeof(*paF)/4;
  266.     }
  267.     {
  268.         register float *paF,*pbF;
  269.  
  270.         n/=sizeof(*paF)/4;
  271.         paF=(float *)buffer;
  272.         pbF=(float *)buffer2;
  273.         StartTimer(timer);
  274.         for(iL=n/10;iL>0;iL--){
  275.             *paF++=*pbF++;
  276.             *paF++=*pbF++;
  277.             *paF++=*pbF++;
  278.             *paF++=*pbF++;
  279.             *paF++=*pbF++;
  280.             *paF++=*pbF++;
  281.             *paF++=*pbF++;
  282.             *paF++=*pbF++;
  283.             *paF++=*pbF++;
  284.             *paF++=*pbF++;
  285.         }
  286.         s=StopTimerSecs(timer)/n-overhead;
  287.         ffprintf(o,"%11.3f µs    *paF++=*pbF++;        // float, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  288.         n*=sizeof(*paF)/4;
  289.     }
  290.     {
  291.         register float *paF,*pbF;
  292.  
  293.         n/=sizeof(*paF)/4;
  294.         paF=(void *)buffer;
  295.         pbF=(void *)buffer2;
  296.         paF--;pbF--;
  297.         StartTimer(timer);
  298.         for(iL=n/10;iL>0;iL--){
  299.             *++paF=*++pbF;
  300.             *++paF=*++pbF;
  301.             *++paF=*++pbF;
  302.             *++paF=*++pbF;
  303.             *++paF=*++pbF;
  304.             *++paF=*++pbF;
  305.             *++paF=*++pbF;
  306.             *++paF=*++pbF;
  307.             *++paF=*++pbF;
  308.             *++paF=*++pbF;
  309.         }
  310.         s=StopTimerSecs(timer)/n-overhead;
  311.         ffprintf(o,"%11.3f µs    *++paF=*++pbF;        // float, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paF)*1e-6/s);
  312.         n*=sizeof(*paF)/4;
  313.     }
  314.     {
  315.         paL=(void *)buffer;
  316.         pbL=(void *)buffer2;
  317.         StartTimer(timer);
  318.         for(iL=n/10;iL>0;iL--){
  319.             *paL++=*pbL++;
  320.             *paL++=*pbL++;
  321.             *paL++=*pbL++;
  322.             *paL++=*pbL++;
  323.             *paL++=*pbL++;
  324.             *paL++=*pbL++;
  325.             *paL++=*pbL++;
  326.             *paL++=*pbL++;
  327.             *paL++=*pbL++;
  328.             *paL++=*pbL++;
  329.         }
  330.         s=StopTimerSecs(timer)/n-overhead;
  331.         ffprintf(o,"%11.3f µs    *paL++=*pbL++;        // long, memory to memory, %.1f MB/s\n",s*1e6,sizeof(*paL)*1e-6/s);
  332.     }
  333.  
  334.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  335.     if(quickDraw>=gestalt8BitQD){
  336.         device=GetMainDevice();
  337.         if(device!=NULL){
  338.             paL=(long *)(**(**device).gdPMap).baseAddr;
  339.             if(paL!=NULL){
  340.                 signed char mode=true32b;
  341.                 long *pSave=paL;
  342.                 
  343.                 StartTimer(timer);
  344.                 if(can32)SwapMMUMode((void *)&mode);
  345.                 for(iL=n/10;iL>0;iL--) paL-=10;
  346.                 if(can32)SwapMMUMode((void *)&mode);
  347.                 s0=StopTimerSecs(timer)/n-overhead;
  348.                 paL=pSave;
  349.                 pbL=(long *)buffer2;
  350.                 StartTimer(timer);
  351.                 if(can32)SwapMMUMode((void *)&mode);
  352.                 for(iL=n/10;iL>0;iL--){
  353.                     *paL++=*pbL++;
  354.                     *paL++=*pbL++;
  355.                     *paL++=*pbL++;
  356.                     *paL++=*pbL++;
  357.                     *paL++=*pbL++;
  358.                     *paL++=*pbL++;
  359.                     *paL++=*pbL++;
  360.                     *paL++=*pbL++;
  361.                     *paL++=*pbL++;
  362.                     *paL++=*pbL++;
  363.                     paL-=10;
  364.                 }
  365.                 if(can32)SwapMMUMode((void *)&mode);
  366.                 s=StopTimerSecs(timer)/n-overhead;
  367.                 s-=s0;                                    // remove time for the paL-=10;
  368.                 ffprintf(o,"%11.3f µs    *paL++=*pbL++;        // long, memory to video mem. %.1f MB/s\n",s*1e6,4e-6/s);
  369.  
  370.                 {
  371.                     Boolean tryIt=1;
  372.                     char *blockMoveName;
  373.  
  374.                     //if(pci)tryIt=Choose(tryIt,"\nTry using BlockMoveDataUncached to copy from memory to video buffer?\n",noYes,2);
  375.                     //else tryIt=Choose(tryIt,"\nTry using BlockMoveData to copy from memory to video buffer?\n",noYes,2);
  376.                     if(tryIt){
  377.                         // this fails on some Macs
  378.                         if(pci)blockMoveName="BlockMoveDataUncached";
  379.                         else blockMoveName="BlockMoveData";
  380.                         paL=pSave;
  381.                         pbL=(long *)buffer2;
  382.                         BlockMoveData(paL,pbL,4*n);    // first copy from screen to memory, so we won't mess up screen
  383.                         StartTimer(timer);
  384.                         if(pci)BlockMoveDataUncached(pbL,paL,4*n);
  385.                         else BlockMoveData(pbL,paL,4*n);
  386.                         s=StopTimerSecs(timer)-overhead;
  387.                         ffprintf(o,"%11.3f ms    %s(,,%ld);    // mem.to vid.mem. %.1f MB/s\n"
  388.                             ,s*1e3,blockMoveName,n*4,n*4/1024./1024./s);
  389.                     }
  390.                     if(tryIt && pci){
  391.                         // this fails on some Macs
  392.                         blockMoveName="BlockCopy";
  393.                         paL=pSave;
  394.                         pbL=(long *)buffer2;
  395.                         BlockMoveData(paL,pbL,4*n);    // first copy from screen to memory, so we won't mess up screen
  396.                         StartTimer(timer);
  397.                         BlockCopy(pbL,paL,4*n);
  398.                         s=StopTimerSecs(timer)-overhead;
  399.                         ffprintf(o,"%11.3f ms    %s(,,%ld);    // mem.to vid.mem. %.1f MB/s\n"
  400.                             ,s*1e3,blockMoveName,n*4,n*4/1024./1024./s);
  401.                     }
  402.                 }
  403.             }
  404.         }
  405.     }
  406.     DisposeHandle(bufferHandle);
  407.     buffer=buffer2=NULL;
  408.  
  409. // Time the VideoToolbox routines that copy images (based on CopyBits and CopyBitsQuickly).
  410.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  411.     if(quickDraw>=gestalt8BitQD){
  412.         unsigned long row[256],row2[256];
  413.         int rowLength=256,clutSize;
  414.         
  415.         assert(StackSpace()>4000);
  416.         n/=100;
  417.         device=GetMainDevice();
  418.         clutSize=GDClutSize(device);
  419.         for(i=0;i<rowLength;i++)row[i]=nrand(clutSize);
  420.         StartTimer(timer);
  421.         for(iL=n;iL>0;iL--){
  422.             SetDevicePixelsQuickly(device,0,0,row,rowLength);
  423.         }
  424.         // NOTE: if you single step through this in the Debugger
  425.         // you'll get an apparent read-back error if the Debugger
  426.         // redraws the Menu bar between writing and reading the pixels.
  427.         s=StopTimerSecs(timer)/n-overhead;
  428.         GetDevicePixelsQuickly(device,0,0,row2,rowLength);
  429.         ffprintf(o,"%11.3f ms    SetPixelsQuickly(,,,,%d);// %d-bit pixels, %.3f MB/s\n",s*1e3
  430.             ,(int)rowLength,(int)(**(**device).gdPMap).pixelSize
  431.             ,(double)rowLength*(**(**device).gdPMap).pixelSize/8/1024/1024/s);
  432.  
  433.         StartTimer(timer);
  434.         for(iL=n;iL>0;iL--){
  435.             GetDevicePixelsQuickly(device,0,0,row,rowLength);
  436.         }
  437.         s=StopTimerSecs(timer)/n-overhead;
  438.         ffprintf(o,"%11.3f ms    GetPixelsQuickly(,,,,%d);// %d-bit pixels, %.3f MB/s\n",s*1e3
  439.             ,(int)rowLength,(int)(**(**device).gdPMap).pixelSize
  440.             ,(double)rowLength*(**(**device).gdPMap).pixelSize/8/1024/1024/s);
  441.         n*=100;
  442.  
  443.         for(i=0;i<1;i++)if(row2[i]!=row[i])printf("Pixel %d: wrote %ld != read %ld\n"
  444.             ,(int)i,row[i],row2[i]);
  445.  
  446.     }
  447.  
  448.     if(quickDraw>=gestalt32BitQD){
  449.         GWorldPtr aWorld,bWorld;
  450.         Rect r;
  451.         int error,pixelSize;
  452.         double pixels;
  453.  
  454.         n=2;
  455.         SetRect(&r,0,0,100,100);
  456.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  457.         error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  458.         if(!error)error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  459.         if(!error){
  460.             LockPixels(GetGWorldPixMap(aWorld));
  461.             LockPixels(GetGWorldPixMap(bWorld));
  462.             StartTimer(timer);
  463.             for(iL=n;iL>0;iL--){
  464.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&aWorld->portRect,srcCopy,NULL);
  465.             }
  466.             s=StopTimerSecs(timer)/n-overhead;
  467.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  468.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%dx%d, %.3f MB/s\n"
  469.                 ,s*1e3,(int)r.right,(int)r.bottom
  470.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  471.         }
  472.         DisposeGWorld(aWorld);
  473.         DisposeGWorld(bWorld);
  474.         SetRect(&r,0,0,100,100);
  475.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  476.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  477.         ShrinkRect(&r,20,1);
  478.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  479.         if(!error){
  480.             LockPixels(GetGWorldPixMap(aWorld));
  481.             LockPixels(GetGWorldPixMap(bWorld));
  482.             StartTimer(timer);
  483.             for(iL=n;iL>0;iL--){
  484.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopy,NULL);
  485.             }
  486.             s=StopTimerSecs(timer)/n-overhead;
  487.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  488.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  489.                 ,s*1e3
  490.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  491.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  492.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  493.         }
  494.         DisposeGWorld(aWorld);
  495.         DisposeGWorld(bWorld);
  496.         SetRect(&r,0,0,100,100);
  497.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  498.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  499.         ShrinkRect(&r,1,20);
  500.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  501.         if(!error){
  502.             LockPixels(GetGWorldPixMap(aWorld));
  503.             LockPixels(GetGWorldPixMap(bWorld));
  504.             StartTimer(timer);
  505.             for(iL=n;iL>0;iL--){
  506.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopy,NULL);
  507.             }
  508.             s=StopTimerSecs(timer)/n-overhead;
  509.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  510.             r=aWorld->portRect;
  511.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopy,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  512.                 ,s*1e3
  513.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  514.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  515.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  516.         }
  517.         DisposeGWorld(aWorld);
  518.         DisposeGWorld(bWorld);
  519.         n=100000;
  520.     }
  521.     if(quickDraw>=gestalt32BitQD){
  522.         GWorldPtr aWorld,bWorld;
  523.         Rect r;
  524.         int error,pixelSize;
  525.         double pixels;
  526.  
  527.         n=2;
  528.         SetRect(&r,0,0,100,100);
  529.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  530.         error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  531.         if(!error)error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  532.         if(!error){
  533.             LockPixels(GetGWorldPixMap(aWorld));
  534.             LockPixels(GetGWorldPixMap(bWorld));
  535.             StartTimer(timer);
  536.             for(iL=n;iL>0;iL--){
  537.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&aWorld->portRect,srcCopyLiterally,NULL);
  538.             }
  539.             s=StopTimerSecs(timer)/n-overhead;
  540.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  541.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%dx%d, %.3f MB/s\n"
  542.                 ,s*1e3,(int)r.right,(int)r.bottom
  543.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  544.         }
  545.         DisposeGWorld(aWorld);
  546.         DisposeGWorld(bWorld);
  547.         SetRect(&r,0,0,100,100);
  548.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  549.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  550.         ShrinkRect(&r,20,1);
  551.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  552.         if(!error){
  553.             LockPixels(GetGWorldPixMap(aWorld));
  554.             LockPixels(GetGWorldPixMap(bWorld));
  555.             StartTimer(timer);
  556.             for(iL=n;iL>0;iL--){
  557.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopyLiterally,NULL);
  558.             }
  559.             s=StopTimerSecs(timer)/n-overhead;
  560.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  561.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  562.                 ,s*1e3
  563.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  564.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  565.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  566.         }
  567.         DisposeGWorld(aWorld);
  568.         DisposeGWorld(bWorld);
  569.         SetRect(&r,0,0,100,100);
  570.         pixels=(double)(r.right-r.left)*(r.bottom-r.top);
  571.         error=NewGWorld(&bWorld,8,&r,NULL,NULL,0);
  572.         ShrinkRect(&r,1,20);
  573.         if(!error)error=NewGWorld(&aWorld,8,&r,NULL,NULL,0);
  574.         if(!error){
  575.             LockPixels(GetGWorldPixMap(aWorld));
  576.             LockPixels(GetGWorldPixMap(bWorld));
  577.             StartTimer(timer);
  578.             for(iL=n;iL>0;iL--){
  579.                 CopyWindows(aWorld,bWorld,&aWorld->portRect,&bWorld->portRect,srcCopyLiterally,NULL);
  580.             }
  581.             s=StopTimerSecs(timer)/n-overhead;
  582.             pixelSize=(**GetGWorldPixMap(aWorld)).pixelSize;
  583.             r=aWorld->portRect;
  584.             ffprintf(o,"%11.3f ms    CopyWindows(,,,,srcCopyLiterally,);// %dx%d to %dx%dx%d, %.3f MB/s\n"
  585.                 ,s*1e3
  586.                 ,(int)aWorld->portRect.right,(int)aWorld->portRect.bottom
  587.                 ,(int)bWorld->portRect.right,(int)bWorld->portRect.bottom
  588.                 ,pixelSize,pixels*pixelSize/8/1024/1024/s);
  589.         }
  590.         DisposeGWorld(aWorld);
  591.         DisposeGWorld(bWorld);
  592.         n=100000;
  593.     }
  594.  
  595.     if(1){            // time long arithmetic
  596.         StartTimer(timer);
  597.         for(iL=n/10;iL>0;iL--){
  598.             jL=kL;
  599.             jL=kL;
  600.             jL=kL;
  601.             jL=kL;
  602.             jL=kL;
  603.             jL=kL;
  604.             jL=kL;
  605.             jL=kL;
  606.             jL=kL;
  607.             jL=kL;
  608.         }
  609.         s=StopTimerSecs(timer)/n-overhead;
  610.         ffprintf(o,"%11.3f µs    jL=kL;            // long, register to register\n",s*1e6);
  611.     
  612.         StartTimer(timer);
  613.         for(iL=n/10;iL>0;iL--){
  614.             jL=kL>>1;
  615.             jL=kL>>1;
  616.             jL=kL>>1;
  617.             jL=kL>>1;
  618.             jL=kL>>1;
  619.             jL=kL>>1;
  620.             jL=kL>>1;
  621.             jL=kL>>1;
  622.             jL=kL>>1;
  623.             jL=kL>>1;
  624.         }
  625.         s=StopTimerSecs(timer)/n-overhead;
  626.         ffprintf(o,"%11.3f µs    jL=kL>>1;\n",s*1e6);
  627.     
  628.         StartTimer(timer);
  629.         for(iL=n/10;iL>0;iL--){
  630.             jL=kL+mL;
  631.             jL=kL+mL;
  632.             jL=kL+mL;
  633.             jL=kL+mL;
  634.             jL=kL+mL;
  635.             jL=kL+mL;
  636.             jL=kL+mL;
  637.             jL=kL+mL;
  638.             jL=kL+mL;
  639.             jL=kL+mL;
  640.         }
  641.         s=StopTimerSecs(timer)/n-overhead;
  642.         ffprintf(o,"%11.3f µs    jL=kL+mL;\n",s*1e6);
  643.     
  644.         StartTimer(timer);
  645.         for(iL=n/10;iL>0;iL--){
  646.             jL=kL-mL;
  647.             jL=kL-mL;
  648.             jL=kL-mL;
  649.             jL=kL-mL;
  650.             jL=kL-mL;
  651.             jL=kL-mL;
  652.             jL=kL-mL;
  653.             jL=kL-mL;
  654.             jL=kL-mL;
  655.             jL=kL-mL;
  656.         }
  657.         s=StopTimerSecs(timer)/n-overhead;
  658.         ffprintf(o,"%11.3f µs    jL=kL-mL;\n",s*1e6);
  659.     
  660.         n/=10;            /* all other operations take at least several microseconds */
  661.         StartTimer(timer);
  662.         for(iL=n/10;iL>0;iL--){
  663.             jL=kL*mL;
  664.             jL=kL*mL;
  665.             jL=kL*mL;
  666.             jL=kL*mL;
  667.             jL=kL*mL;
  668.             jL=kL*mL;
  669.             jL=kL*mL;
  670.             jL=kL*mL;
  671.             jL=kL*mL;
  672.             jL=kL*mL;
  673.         }
  674.         s=StopTimerSecs(timer)/n-overhead;
  675.         ffprintf(o,"%11.3f µs    jL=kL*mL;\n",s*1e6);
  676.     
  677.         StartTimer(timer);
  678.         for(iL=n/10;iL>0;iL--){
  679.             jL=kL/mL;
  680.             jL=kL/mL;
  681.             jL=kL/mL;
  682.             jL=kL/mL;
  683.             jL=kL/mL;
  684.             jL=kL/mL;
  685.             jL=kL/mL;
  686.             jL=kL/mL;
  687.             jL=kL/mL;
  688.             jL=kL/mL;
  689.         }
  690.         s=StopTimerSecs(timer)/n-overhead;
  691.         ffprintf(o,"%11.3f µs    jL=kL/mL;\n",s*1e6);
  692.         n*=10;
  693.     }
  694.     if(1){                // time short arithmetic
  695.         register short jH,kH=1234,mH=5678;
  696.         
  697.         StartTimer(timer);
  698.         for(iL=n/10;iL>0;iL--){
  699.             jH=kH;
  700.             jH=kH;
  701.             jH=kH;
  702.             jH=kH;
  703.             jH=kH;
  704.             jH=kH;
  705.             jH=kH;
  706.             jH=kH;
  707.             jH=kH;
  708.             jH=kH;
  709.         }
  710.         s=StopTimerSecs(timer)/n-overhead;
  711.         ffprintf(o,"%11.3f µs    jH=kH;            // short, register to register\n",s*1e6);
  712.     
  713.         StartTimer(timer);
  714.         for(iL=n/10;iL>0;iL--){
  715.             jH=kH>>1;
  716.             jH=kH>>1;
  717.             jH=kH>>1;
  718.             jH=kH>>1;
  719.             jH=kH>>1;
  720.             jH=kH>>1;
  721.             jH=kH>>1;
  722.             jH=kH>>1;
  723.             jH=kH>>1;
  724.             jH=kH>>1;
  725.         }
  726.         s=StopTimerSecs(timer)/n-overhead;
  727.         ffprintf(o,"%11.3f µs    jH=kH>>1;\n",s*1e6);
  728.     
  729.         StartTimer(timer);
  730.         for(iL=n/10;iL>0;iL--){
  731.             jH=kH+mH;
  732.             jH=kH+mH;
  733.             jH=kH+mH;
  734.             jH=kH+mH;
  735.             jH=kH+mH;
  736.             jH=kH+mH;
  737.             jH=kH+mH;
  738.             jH=kH+mH;
  739.             jH=kH+mH;
  740.             jH=kH+mH;
  741.         }
  742.         s=StopTimerSecs(timer)/n-overhead;
  743.         ffprintf(o,"%11.3f µs    jH=kH+mH;\n",s*1e6);
  744.     
  745.         StartTimer(timer);
  746.         for(iL=n/10;iL>0;iL--){
  747.             jH=kH-mH;
  748.             jH=kH-mH;
  749.             jH=kH-mH;
  750.             jH=kH-mH;
  751.             jH=kH-mH;
  752.             jH=kH-mH;
  753.             jH=kH-mH;
  754.             jH=kH-mH;
  755.             jH=kH-mH;
  756.             jH=kH-mH;
  757.         }
  758.         s=StopTimerSecs(timer)/n-overhead;
  759.         ffprintf(o,"%11.3f µs    jH=kH-mH;\n",s*1e6);
  760.     
  761.         n/=10;            /* all other operations take at least several microseconds */
  762.         StartTimer(timer);
  763.         for(iL=n/10;iL>0;iL--){
  764.             jH=kH*mH;
  765.             jH=kH*mH;
  766.             jH=kH*mH;
  767.             jH=kH*mH;
  768.             jH=kH*mH;
  769.             jH=kH*mH;
  770.             jH=kH*mH;
  771.             jH=kH*mH;
  772.             jH=kH*mH;
  773.             jH=kH*mH;
  774.         }
  775.         s=StopTimerSecs(timer)/n-overhead;
  776.         ffprintf(o,"%11.3f µs    jH=kH*mH;\n",s*1e6);
  777.     
  778.         StartTimer(timer);
  779.         for(iL=n/10;iL>0;iL--){
  780.             jH=kH/mH;
  781.             jH=kH/mH;
  782.             jH=kH/mH;
  783.             jH=kH/mH;
  784.             jH=kH/mH;
  785.             jH=kH/mH;
  786.             jH=kH/mH;
  787.             jH=kH/mH;
  788.             jH=kH/mH;
  789.             jH=kH/mH;
  790.         }
  791.         s=StopTimerSecs(timer)/n-overhead;
  792.         ffprintf(o,"%11.3f µs    jH=kH/mH;\n",s*1e6);
  793.         n*=10;
  794.     }
  795.  
  796.     n/=10;            /* all other operations take at least several microseconds */
  797.  
  798.     if(1){        // time double arithmetic
  799.         StartTimer(timer);
  800.         for(iL=n/10;iL>0;iL--){
  801.             x=y;
  802.             x=y;
  803.             x=y;
  804.             x=y;
  805.             x=y;
  806.             x=y;
  807.             x=y;
  808.             x=y;
  809.             x=y;
  810.             x=y;
  811.         }
  812.         s=StopTimerSecs(timer)/n-overhead;
  813.         ffprintf(o,"%11.3f µs    x=y;            // double\n",s*1e6);
  814.     
  815.         StartTimer(timer);
  816.         for(iL=n/10;iL>0;iL--){
  817.             x=y+z;
  818.             x=y+z;
  819.             x=y+z;
  820.             x=y+z;
  821.             x=y+z;
  822.             x=y+z;
  823.             x=y+z;
  824.             x=y+z;
  825.             x=y+z;
  826.             x=y+z;
  827.         }
  828.         s=StopTimerSecs(timer)/n-overhead;
  829.         ffprintf(o,"%11.3f µs    x=y+z;\n",s*1e6);
  830.     
  831.         StartTimer(timer);
  832.         for(iL=n/10;iL>0;iL--){
  833.             x=y-z;
  834.             x=y-z;
  835.             x=y-z;
  836.             x=y-z;
  837.             x=y-z;
  838.             x=y-z;
  839.             x=y-z;
  840.             x=y-z;
  841.             x=y-z;
  842.             x=y-z;
  843.         }
  844.         s=StopTimerSecs(timer)/n-overhead;
  845.         ffprintf(o,"%11.3f µs    x=y-z;\n",s*1e6);
  846.     
  847.         StartTimer(timer);
  848.         for(iL=n/10;iL>0;iL--){
  849.             x=y*z;
  850.             x=y*z;
  851.             x=y*z;
  852.             x=y*z;
  853.             x=y*z;
  854.             x=y*z;
  855.             x=y*z;
  856.             x=y*z;
  857.             x=y*z;
  858.             x=y*z;
  859.         }
  860.         s=StopTimerSecs(timer)/n-overhead;
  861.         ffprintf(o,"%11.3f µs    x=y*z;\n",s*1e6);
  862.     
  863.         StartTimer(timer);
  864.         for(iL=n/10;iL>0;iL--){
  865.             x=y/z;
  866.             x=y/z;
  867.             x=y/z;
  868.             x=y/z;
  869.             x=y/z;
  870.             x=y/z;
  871.             x=y/z;
  872.             x=y/z;
  873.             x=y/z;
  874.             x=y/z;
  875.         }
  876.         s=StopTimerSecs(timer)/n-overhead;
  877.         ffprintf(o,"%11.3f µs    x=y/z;\n",s*1e6);
  878.     }
  879.     
  880.     if(1){                // time transcendental functions
  881.         StartTimer(timer);
  882.         for(iL=n/10;iL>0;iL--){
  883.             x=sin(y);
  884.             x=sin(y);
  885.             x=sin(y);
  886.             x=sin(y);
  887.             x=sin(y);
  888.             x=sin(y);
  889.             x=sin(y);
  890.             x=sin(y);
  891.             x=sin(y);
  892.             x=sin(y);
  893.         }
  894.         s=StopTimerSecs(timer)/n-overhead;
  895.         ffprintf(o,"%11.3f µs    x=sin(y);\n",s*1e6);
  896.     
  897.         StartTimer(timer);
  898.         for(iL=n/10;iL>0;iL--){
  899.             x=sqrt(y);
  900.             x=sqrt(y);
  901.             x=sqrt(y);
  902.             x=sqrt(y);
  903.             x=sqrt(y);
  904.             x=sqrt(y);
  905.             x=sqrt(y);
  906.             x=sqrt(y);
  907.             x=sqrt(y);
  908.             x=sqrt(y);
  909.         }
  910.         s=StopTimerSecs(timer)/n-overhead;
  911.         ffprintf(o,"%11.3f µs    x=sqrt(y);\n",s*1e6);
  912.     
  913.         n/=100;
  914.         StartTimer(timer);
  915.         for(iL=n/10;iL>0;iL--){
  916.             x=log(y);
  917.             x=log(y);
  918.             x=log(y);
  919.             x=log(y);
  920.             x=log(y);
  921.             x=log(y);
  922.             x=log(y);
  923.             x=log(y);
  924.             x=log(y);
  925.             x=log(y);
  926.         }
  927.         s=StopTimerSecs(timer)/n-overhead;
  928.         ffprintf(o,"%11.3f µs    x=log(y);\n",s*1e6);
  929.         StartTimer(timer);
  930.         for(iL=n/10;iL>0;iL--){
  931.             x=exp(y);
  932.             x=exp(y);
  933.             x=exp(y);
  934.             x=exp(y);
  935.             x=exp(y);
  936.             x=exp(y);
  937.             x=exp(y);
  938.             x=exp(y);
  939.             x=exp(y);
  940.             x=exp(y);
  941.         }
  942.         s=StopTimerSecs(timer)/n-overhead;
  943.         ffprintf(o,"%11.3f µs    x=exp(y);\n",s*1e6);
  944.         n*=100;
  945.     
  946.     }
  947.  
  948.     o[1]=NULL;        /* that's all we want to save in “TimeCPU results” */
  949.  
  950.     if(1){                    // time Fixed
  951.         yF=zF=0x12341234;
  952.         StartTimer(timer);
  953.         for(iL=n/10;iL>0;iL--){
  954.             xF=FixMul(yF,zF);
  955.             xF=FixMul(yF,zF);
  956.             xF=FixMul(yF,zF);
  957.             xF=FixMul(yF,zF);
  958.             xF=FixMul(yF,zF);
  959.             xF=FixMul(yF,zF);
  960.             xF=FixMul(yF,zF);
  961.             xF=FixMul(yF,zF);
  962.             xF=FixMul(yF,zF);
  963.             xF=FixMul(yF,zF);
  964.         }
  965.         s=StopTimerSecs(timer)/n-overhead;
  966.         ffprintf(o,"%11.3f µs    xF=FixMul(yF,zF);    // Fixed\n",s*1e6);
  967.     
  968.         yF=(long)(PI*256);
  969.         zF=(long)(1.1*256);
  970.         StartTimer(timer);
  971.         for(iL=n/10;iL>0;iL--){
  972.             xF=FixDiv(yF,zF);
  973.             xF=FixDiv(yF,zF);
  974.             xF=FixDiv(yF,zF);
  975.             xF=FixDiv(yF,zF);
  976.             xF=FixDiv(yF,zF);
  977.             xF=FixDiv(yF,zF);
  978.             xF=FixDiv(yF,zF);
  979.             xF=FixDiv(yF,zF);
  980.             xF=FixDiv(yF,zF);
  981.             xF=FixDiv(yF,zF);
  982.         }
  983.         s=StopTimerSecs(timer)/n-overhead;
  984.         ffprintf(o,"%11.3f µs    xF=FixDiv(yF,zF);\n",s*1e6);
  985.     
  986.         StartTimer(timer);
  987.         for(iL=n/10;iL>0;iL--){
  988.             xF=FixRatio(123,1234);
  989.             xF=FixRatio(123,1234);
  990.             xF=FixRatio(123,1234);
  991.             xF=FixRatio(123,1234);
  992.             xF=FixRatio(123,1234);
  993.             xF=FixRatio(123,1234);
  994.             xF=FixRatio(123,1234);
  995.             xF=FixRatio(123,1234);
  996.             xF=FixRatio(123,1234);
  997.             xF=FixRatio(123,1234);
  998.         }
  999.         s=StopTimerSecs(timer)/n-overhead;
  1000.         ffprintf(o,"%11.3f µs    xF=FixRatio(123,1234);\n",s*1e6);
  1001.     
  1002.         StartTimer(timer);
  1003.         for(iL=n/10;iL>0;iL--){
  1004.             xF=DoubleToFix(y);
  1005.             xF=DoubleToFix(y);
  1006.             xF=DoubleToFix(y);
  1007.             xF=DoubleToFix(y);
  1008.             xF=DoubleToFix(y);
  1009.             xF=DoubleToFix(y);
  1010.             xF=DoubleToFix(y);
  1011.             xF=DoubleToFix(y);
  1012.             xF=DoubleToFix(y);
  1013.             xF=DoubleToFix(y);
  1014.         }
  1015.         s=StopTimerSecs(timer)/n-overhead;
  1016.         ffprintf(o,"%11.3f µs    xF=DoubleToFix(y);\n",s*1e6);
  1017.     
  1018.         xF=(long)(PI*256);
  1019.         StartTimer(timer);
  1020.         for(iL=n/10;iL>0;iL--){
  1021.             x=FixToDouble(xF);
  1022.             x=FixToDouble(xF);
  1023.             x=FixToDouble(xF);
  1024.             x=FixToDouble(xF);
  1025.             x=FixToDouble(xF);
  1026.             x=FixToDouble(xF);
  1027.             x=FixToDouble(xF);
  1028.             x=FixToDouble(xF);
  1029.             x=FixToDouble(xF);
  1030.             x=FixToDouble(xF);
  1031.             x=FixToDouble(xF);
  1032.         }
  1033.         s=StopTimerSecs(timer)/n-overhead;
  1034.         ffprintf(o,"%11.3f µs    x=FixToDouble(xF);\n",s*1e6);
  1035.     }
  1036.     
  1037.     if(1){                // time rand()
  1038.         n*=10;
  1039.         for(;n>0;){
  1040.             bufferHandle=NewHandle(n);
  1041.             if(bufferHandle==NULL)bufferHandle=TempNewHandle(n,&osErr);
  1042.             if(bufferHandle!=NULL)break;
  1043.             n/=2;
  1044.             printf("Reducing iterations to %ld to fit in available memory.\n",n);
  1045.         }
  1046.         assert(bufferHandle!=NULL);
  1047.         HLockHi(bufferHandle);
  1048.         buffer=*bufferHandle;
  1049.         StartTimer(timer);
  1050.         s=StopTimerSecs(timer);
  1051.         StartTimer(timer);
  1052.         RandFill(buffer,n);
  1053.         s=StopTimerSecs(timer) - s;
  1054.         DisposeHandle(bufferHandle);
  1055.         buffer=NULL;
  1056.         ffprintf(o,"%11.3f µs    RandFill(,%ld);    // i.e. %4.1f µs/byte\n"
  1057.             ,s*1e6,n,s*1e6/n);
  1058.         n/=10;
  1059.     
  1060.         StartTimer(timer);
  1061.         for(iL=n/10;iL>0;iL--){
  1062.             i=randU();
  1063.             i=randU();
  1064.             i=randU();
  1065.             i=randU();
  1066.             i=randU();
  1067.             i=randU();
  1068.             i=randU();
  1069.             i=randU();
  1070.             i=randU();
  1071.             i=randU();
  1072.         }
  1073.         s=StopTimerSecs(timer)/n-overhead;
  1074.         ffprintf(o,"%11.3f µs    i=randU();        // i.e. %4.1f µs/byte\n",s*1e6, s*1e6/2.);
  1075.     
  1076.         StartTimer(timer);
  1077.         for(iL=n/10;iL>0;iL--){
  1078.             i=rand();
  1079.             i=rand();
  1080.             i=rand();
  1081.             i=rand();
  1082.             i=rand();
  1083.             i=rand();
  1084.             i=rand();
  1085.             i=rand();
  1086.             i=rand();
  1087.             i=rand();
  1088.         }
  1089.         s=StopTimerSecs(timer)/n-overhead;
  1090.         ffprintf(o,"%11.3f µs    i=rand();         // i.e. %4.1f µs/byte\n",s*1e6, s*1e6/1.);
  1091.     
  1092.         StartTimer(timer);
  1093.         for(iL=n/10;iL>0;iL--){
  1094.             i=Random();
  1095.             i=Random();
  1096.             i=Random();
  1097.             i=Random();
  1098.             i=Random();
  1099.             i=Random();
  1100.             i=Random();
  1101.             i=Random();
  1102.             i=Random();
  1103.             i=Random();
  1104.         }
  1105.         s=StopTimerSecs(timer)/n-overhead;
  1106.         ffprintf(o,"%11.3f µs    i=Random();\n",s*1e6);
  1107.     
  1108.         StartTimer(timer);
  1109.         for(iL=n/10;iL>0;iL--){
  1110.             i=nrand(127);
  1111.             i=nrand(127);
  1112.             i=nrand(127);
  1113.             i=nrand(127);
  1114.             i=nrand(127);
  1115.             i=nrand(127);
  1116.             i=nrand(127);
  1117.             i=nrand(127);
  1118.             i=nrand(127);
  1119.             i=nrand(127);
  1120.         }
  1121.         s=StopTimerSecs(timer)/n-overhead;
  1122.         ffprintf(o,"%11.3f µs    i=nrand(127);\n",s*1e6);
  1123.     
  1124.         StartTimer(timer);
  1125.         for(iL=n/10;iL>0;iL--){
  1126.             i=127L*randU()>>16;
  1127.             i=127L*randU()>>16;
  1128.             i=127L*randU()>>16;
  1129.             i=127L*randU()>>16;
  1130.             i=127L*randU()>>16;
  1131.             i=127L*randU()>>16;
  1132.             i=127L*randU()>>16;
  1133.             i=127L*randU()>>16;
  1134.             i=127L*randU()>>16;
  1135.             i=127L*randU()>>16;
  1136.         }
  1137.         s=StopTimerSecs(timer)/n-overhead;
  1138.         ffprintf(o,"%11.3f µs    i=127L*randU()>>16;\n",s*1e6);
  1139.     
  1140.         StartTimer(timer);
  1141.         for(iL=n/10;iL>0;iL--){
  1142.             i=127L*rand()>>15;
  1143.             i=127L*rand()>>15;
  1144.             i=127L*rand()>>15;
  1145.             i=127L*rand()>>15;
  1146.             i=127L*rand()>>15;
  1147.             i=127L*rand()>>15;
  1148.             i=127L*rand()>>15;
  1149.             i=127L*rand()>>15;
  1150.             i=127L*rand()>>15;
  1151.             i=127L*rand()>>15;
  1152.         }
  1153.         s=StopTimerSecs(timer)/n-overhead;
  1154.         ffprintf(o,"%11.3f µs    i=127L*rand()>>15;\n",s*1e6);
  1155.     
  1156.         StartTimer(timer);
  1157.         for(iL=n/10;iL>0;iL--){
  1158.             i=randU()%(unsigned short)127;
  1159.             i=randU()%(unsigned short)127;
  1160.             i=randU()%(unsigned short)127;
  1161.             i=randU()%(unsigned short)127;
  1162.             i=randU()%(unsigned short)127;
  1163.             i=randU()%(unsigned short)127;
  1164.             i=randU()%(unsigned short)127;
  1165.             i=randU()%(unsigned short)127;
  1166.             i=randU()%(unsigned short)127;
  1167.             i=randU()%(unsigned short)127;
  1168.         }
  1169.         s=StopTimerSecs(timer)/n-overhead;
  1170.         ffprintf(o,"%11.3f µs    i=randU()%%(unsigned short)127;\n",s*1e6);
  1171.     
  1172.         StartTimer(timer);
  1173.         for(iL=n/10;iL>0;iL--){
  1174.             i=rand()%127;
  1175.             i=rand()%127;
  1176.             i=rand()%127;
  1177.             i=rand()%127;
  1178.             i=rand()%127;
  1179.             i=rand()%127;
  1180.             i=rand()%127;
  1181.             i=rand()%127;
  1182.             i=rand()%127;
  1183.             i=rand()%127;
  1184.         }
  1185.         s=StopTimerSecs(timer)/n-overhead;
  1186.         ffprintf(o,"%11.3f µs    i=rand()%%127;\n",s*1e6);
  1187.     }
  1188.     DisposeTimer(timer);
  1189.     fclose(dataFile);    /* close “TimeCPU results” */
  1190.     DrawMenuBar();
  1191. }
  1192.  
  1193.